/*
 * Reprice.h
 *
 *  Created on: Dec 4, 2009
 *      Author: abhishek
 */

#ifndef REPRICE_H_
#define REPRICE_H_

#include "Node.h"
#include "Headers.h"

struct metadata1{
	int isNodeVisited;
	double originalPrice ;
	double bestDelta ;
	double bestMaxRevenue;
	double originalRevenue ;
	double newRevenue ;
	int iterationNumber ;
};

class heapNode{

public:
	heapNode(){}
	virtual ~heapNode(){}

	void gRevenueIs(double gRevenue) {gRevenue_ = gRevenue ;}
	void nodeIdIs(int nodeId) {nodeId_ = nodeId ;}
	double gRevenue() const {return gRevenue_ ;}
	int nodeId(){return nodeId_ ; }

private:
	int nodeId_;
	double gRevenue_ ;
};


class trianglesOverlapNode{

public:
	trianglesOverlapNode(){}
	virtual ~trianglesOverlapNode(){}

	void uIs(int u) {u_ = u ;}
	void vIs(int v) {v_ = v ;}
	void numTrianglesIs(int numTriangles)  {numTriangles_ = numTriangles ;}
	void revenueAcrossEdgesIs(double revenueAcrossEdges){revenueAcrossEdges_ = revenueAcrossEdges ;}
	void weightIs(double weight) {weight_ = weight;}

	int u(){return u_ ; }
	int v(){return v_ ;}
	int numTriangles(){return numTriangles_ ;}
	double revenueAcrossEdges(){return revenueAcrossEdges_;}
	double weight(){return weight_ ;}

private:
	int u_;
	int v_ ;
	int numTriangles_ ;
	double revenueAcrossEdges_ ;
	double weight_ ;
};

class Comparator
{
public:
	Comparator(){}

	// for Min heap
  bool operator() ( heapNode*& lhs,  heapNode*& rhs) const{
	  if (lhs->gRevenue() > rhs->gRevenue())
		  return true ;
	  return false;
  }

  // for Max heap
  bool operator() ( trianglesOverlapNode*& lhs,  trianglesOverlapNode*& rhs) const{
  	  if (lhs->weight() < rhs->weight())
  		  return true ;
  	  return false;
    }

};


class Reprice {
public:
	Reprice();
	virtual ~Reprice();

	void readGraph();

	void heuristic1();
	void heuristic2();
	void heuristic3();

	void selectCandidates();

private:


	Node* nodeIdToNodePtrIndex_[NUMNODES];
	heapNode* heapNodesIndex_[NUMNODES];

	// Finding candidates
	priority_queue< heapNode*, vector<heapNode*>, Comparator > queue_ ;
	double gRevenue_[NUMNODES];
	int candidateNodes[TOPK];

	// Strategy 1 and 2
	metadata1 strategy1[NUMNODES];


	// Strategy 3
	map<string, trianglesOverlapNode*> trianglesOverlapMap ;
	priority_queue< trianglesOverlapNode*, vector<trianglesOverlapNode*>, Comparator > queueTrianglesOverlap_ ;


	double totalRevenue_ ;

	void constructTrianglesOverlap();
	void updateF();
	void updateG();
	void updatePrice();
	void updateInfluence();

	void writetoFile(string filename);
};

#endif /* REPRICE_H_ */
